package org.anti996.lms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.anti996.lms.model.Booking;
import org.anti996.lms.model.Customer;
import org.anti996.lms.mapper.CustomerMapper;
import org.anti996.lms.model.Driver;
import org.anti996.lms.model.Warehouse;
import org.anti996.lms.service.CustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 客户表 服务实现类
 * </p>
 *
 * @author The Anti996 Authors
 * @since 2022-07-15
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Override//根据输入的姓名，电话，地址返回到客户编号
    public  Customer getIdbynps(String username,String phone,String address){
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("name",username);
        wrapper.eq("phone",phone);
        wrapper.eq("addr",address);
        return baseMapper.selectOne(wrapper);
    }

    @Override//根据用户姓名获得电话
    public String getPhoneByName(String name) {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name);
        List<Customer> customers=baseMapper.selectList(wrapper);
        Customer customer=customers.get(0);
        return (customer.getPhone());
    }

    @Override//根据客户姓名获得地址
    public String getAddrByName(String name) {
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("name",name);
        List<Customer> customers=baseMapper.selectList(wrapper);
        Customer customer=customers.get(0);
        return (customer.getAddr());
    }

    @Override//判断填表时的客户是否是新客户
    public boolean isexist(String username,String phone,String address){
        QueryWrapper<Customer> wrapper = new QueryWrapper<>();
        wrapper.eq("name",username);
        wrapper.eq("phone",phone);
        wrapper.eq("addr",address);
        return baseMapper.exists(wrapper);
    }

    @Override
    public List<Customer> findCustomersByName(String name) {
        return baseMapper.findCustomersByName("%" + name.trim() + "%");
    }
}
